import tensorflow as tf

distribution = tf.contrib.distributions

def weight_variable(shape):
    initial = tf.truncated_normal(shape, stddev=0.01)
    return tf.Variable(initial)
    
def bias_variable(shape):
    initial = tf.constant(0.1, shape=shape)
    return tf.Variable(initial)
    
def conv2d(x, W):
     return tf.nn.conv2d(x, W, strides=[1,1,1,1], padding='SAME')
    
def loglikelihood(mean_arr, sampled_arr, sigma):
    mu = tf.pack(mean_arr)            # mu = [timesteps, batch_sz, loc_dim]
    sampled = tf.pack(sampled_arr)    # same shape as mu
    gaussian = distribution.Normal(mu, sigma)
    logll = gaussian.log_pdf(sampled) # [timesteps, batch_sz, loc_dim]
    logll = tf.reduce_sum(logll, 2)
    logll = tf.transpose(logll)       # [batch_sz, timesteps]
    return logll

    
